//
// Created by LovingYoung on 11/1/2015.
//

#ifndef HANOI_STATUS_H
#define HANOI_STATUS_H

#include <iostream>
#include <vector>

using namespace std;

namespace liuyang{
    class status{
    private:
        status * parent;
        vector<int> myStatus;
        int level;
        int steps;
    public:
        //Construtor
        status(int m_level,vector<int> m_status):parent(NULL), steps(0), level(m_level),myStatus(m_status){};
        status(int m_level,vector<int> m_status, status * m_parent):parent(m_parent), steps(m_parent->getSteps()), level(m_level),myStatus(m_status){};
        status(const status &a1){
            level = a1.getLevel();
            steps = a1.getSteps();
            myStatus = a1.getStatus();
            parent = a1.getParent();
        }

        const int getLevel() const{
            return level;
        }

        int setLevel(int newLevel){
            level = newLevel;
        }

        int addSteps(){
            steps += 1;
            return steps;
        }

        int decreaseSteps(){
            steps -= 1;
            return steps;
        }

        const int getSteps() const {
            return steps;
        }

        const int getSize() const{
            return myStatus.size();
        }

        const int &operator[](int index) const{
            return myStatus[index];
        }

        const vector<int> getStatus() const{
            return myStatus;
        }

        status * getParent() const{
            return parent;
        }

        bool isComplete(){
            for(int i = 0;i < getSize(); i++){
                if(myStatus[i] != 2) return false;
            }
            return true;
        }

        bool operator == (status & a2){
            if(this->getStatus() == a2.getStatus() && this->getSteps() == a2.getSteps()) return true;
            else return false;
        }



//        const bool operator < (const status & a2) const{
//            if(getLevel() < a2.getLevel()) return true;
//            if(getSteps() < a2.getSteps()) return true;
//
//            vector<int> vec = a2.getStatus();
//
//            for(int i = 0; i < getLevel(); i++){
//                if(this->myStatus[i] < vec[i]) return true;
//            }
//
//            return false;
//        }
        const bool operator < (const status & a2) const{
            vector<int> v1 = this->getStatus();
            vector<int> v2 = a2.getStatus();
            return std::lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end());
        }
    };
//
//    class CompareStatus{
//    public:
//        bool operator()(status & a1, status & a2){
////            if(a1.getLevel() < a2.getLevel()) return true;
////            if(a1.getSteps() < a2.getSteps()) return true;
//
//            for(int i = 0; i < a1.getSize(); i++){
//                if(a1[i] < a2[i]) return true;
//            }
//
//            return false;
//        }
//    };
}

#endif //HANOI_STATUS_H
